@echo off
chcp 65001 >nul 2>&1
echo ==========================================
echo    Quick Restart and Test Gateway
echo ==========================================
echo.

echo [1] 启动Gateway服务...
echo -----------------------------------------
cd Demo5_1\Gateway_Server_9000
echo 正在启动Gateway服务(端口9000)...
start /B mvn spring-boot:run >nul 2>&1
cd ..\..
echo Gateway服务启动命令已执行
echo.

echo [2] 等待服务启动...
echo -----------------------------------------
echo 等待Gateway服务启动(30秒)...
timeout /t 10 >nul

echo [3] 测试认证过滤器工作状态...
echo -----------------------------------------
echo 测试无Token访问(应该返回401):
curl -s -w "Status: %%{http_code}\n" http://localhost:9000/test/auth-required
echo.

echo 测试有Token访问(应该返回200):
curl -s -w "Status: %%{http_code}\n" -H "Authorization: Bearer mytoken" http://localhost:9000/test/auth-required
echo.

echo [4] 测试CORS配置...
echo -----------------------------------------
echo OPTIONS预检请求(应该返回200或204):
curl -s -w "Status: %%{http_code}\n" -X OPTIONS -H "Origin: http://localhost:3000" -H "Access-Control-Request-Method: POST" http://localhost:9000/test/ping
echo.

echo GET请求with Origin(应该有CORS头):
curl -s -i -H "Origin: http://localhost:3000" http://localhost:9000/test/ping | findstr /C:"HTTP" /C:"Access-Control"
echo.

echo ==========================================
echo 如果仍有问题，请检查Gateway控制台日志
echo ==========================================
pause 